<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="content">
        zhwaowmawh
    </div>
    <script>
        let zh = 'baidu.com';
        // 检测字符串中是否包含“u”
        console.log(/u/.test(zh)); // true

        let a = "u";
        // eval方法将字符串转为js表达式
        console.log(eval(`/${a}/`)); // /u/
        console.log(eval(`/${a}/`).test(zh)); // true

        // 创建正则表达式方式
        // let aa = /u/;
        let aa = new RegExp('u', 'g'); // 1.正则 2.匹配模式
        console.log(aa.test(zh))
        let cont = prompt('请输入要检测的内容，支持正则')
        let div = document.querySelector('.content');
        let reg = new RegExp(cont, 'g');
        div.innerHTML = div.innerHTML.replace(reg, search => {
            return `<span style="color:red">${search}</span>`
        });

        let hd = `
            <span>
                houdunren
                hdcms
            </span>
            `;
        let res = hd.match(/<span>[\s\S]+<\/span>/);
        console.log(res[0]);

        let tel = `010 - 999999`;
        console.log(/\d+-\d+/.test(tel)); //false
        console.log(/\d+ - \d+/.test(tel)); //true
    </script>
</body>

</html>